﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Text.RegularExpressions;

namespace WorkPerformanceTool
{
    public partial class Form1 : Form
    {
        private List<string> WORKDAYS = new List<string>();
        /// <summary>
        /// 作業実績管理ツール：        /// 可自动填一个月作業実績
        /// 可查看大连出勤日历
        /// 局域网下载地址：
        /// \\ot2416\商品G専用\10_個人一時保管\max10\作業実績管理
        /// C#代码开源地址：（有好想法可贡献代码）
        /// https://gitee.com/marx99/WorkPerformanceTool
        /// </summary>
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            setButtonStatus(false);
            // 使用帮助全部展开
            treeView1.ExpandAll();
            // 读取INI文件并将内容填写到画面的代填区域
            this.ReadIniAndInput();
            // 笔记本的小屏幕，无法显示整个网页
            Rectangle rec = Screen.GetWorkingArea(this);
            int SH = rec.Height;
            int SW = rec.Width;
            if (SH > 820)
            {
                this.Height = 820;
            }
            else
            {
                this.Height = SH;
            }
        }

        /// <summary>
        /// F2:偷懒模式，出勤作業実績自動入力
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF2_Click(object sender, EventArgs e)
        {
            //打开作业实际管理页
            tabControl11.SelectedIndex = 0;
            if (isExists("ctl00_ContentPlaceHolder1_GrdView_ctl02_TxtSagyouCodeDai"))
            {
                // 画面的代填区域的内容写入INI文件
                this.WriteIni();
                // Check合計作業時間是否为470分（8小时）
                this.checkTotalWorkTime();
                // 节假日时间自动填入
                this.holidayTimeInput(null, null);
                // 作業コード（大）（中）、作業時間（分）、摘要が必須項目
                if (this.checkNull()==false) return;
            }
            else{
                //作業コード（大）控件不存在的时候
                MessageBox.Show("请打开出勤作業実績入力画面", "警告");
            }
        }

        /// <summary>
        /// 读取INI文件并将内容填写到画面的代填区域
        /// </summary>
        private void ReadIniAndInput()
        {
            for (int i = 1; i <= 5;i++ )
            {
                // 读取INI文件
                string[] rowInfo = IniFunc.getString("content", "row" + i.ToString(), "", Application.StartupPath + "\\WorkPerformance.ini").Split(',');
                if (rowInfo.Length < 8)
                {
                    continue;
                }
                // 将内容填写到画面的代填区域
                // chk_select
                CheckBox chk_select = FindControl(this, "chk_select_" + i.ToString()) as CheckBox;
                // 作業コード（大）
                TextBox TxtSagyouCodeDai = FindControl(this, "TxtSagyouCodeDai_" + i.ToString()) as TextBox;
                // 作業コード（中）
                TextBox TxtSagyouCodeTyuu = FindControl(this, "TxtSagyouCodeTyuu_" + i.ToString()) as TextBox;
                // 作業コード（小）
                TextBox TxtSagyouCodeSyou = FindControl(this, "TxtSagyouCodeSyou_" + i.ToString()) as TextBox;
                // 作業時間
                TextBox TxtSagyouJikan = FindControl(this, "TxtSagyouJikan_" + i.ToString()) as TextBox;
                // EDP NO
                TextBox TxtEDP = FindControl(this, "TxtEDP_" + i.ToString()) as TextBox;
                // フリーエリア
                TextBox TxtKubun = FindControl(this, "TxtKubun_" + i.ToString()) as TextBox;
                // 摘要（全角20文字以内）
                TextBox TxtTekiyou = FindControl(this, "TxtTekiyou_" + i.ToString()) as TextBox;
                // Input
                if (rowInfo[0] == "1") chk_select.Checked = true;
                TxtSagyouCodeDai.Text = rowInfo[1];
                TxtSagyouCodeTyuu.Text = rowInfo[2];
                TxtSagyouCodeSyou.Text = rowInfo[3];
                TxtSagyouJikan.Text = rowInfo[4];
                TxtEDP.Text = rowInfo[5];
                TxtKubun.Text = rowInfo[6];
                TxtTekiyou.Text = rowInfo[7];
            }
        }

        /// <summary>
        /// 画面的代填区域的内容写入INI文件
        /// </summary>
        private void WriteIni()
        {
            // 作業実績管理システム入力行数
            int system_count = 1;

            for (int i = 1; i <= 5; i++)
            {
                // 将内容填写到画面的代填区域
                // chk_select
                CheckBox chk_select = FindControl(this, "chk_select_" + i.ToString()) as CheckBox;
                // 作業コード（大）
                TextBox TxtSagyouCodeDai = FindControl(this, "TxtSagyouCodeDai_" + i.ToString()) as TextBox;
                // 作業コード（中）
                TextBox TxtSagyouCodeTyuu = FindControl(this, "TxtSagyouCodeTyuu_" + i.ToString()) as TextBox;
                // 作業コード（小）
                TextBox TxtSagyouCodeSyou = FindControl(this, "TxtSagyouCodeSyou_" + i.ToString()) as TextBox;
                // 作業時間
                TextBox TxtSagyouJikan = FindControl(this, "TxtSagyouJikan_" + i.ToString()) as TextBox;
                // EDP NO
                TextBox TxtEDP = FindControl(this, "TxtEDP_" + i.ToString()) as TextBox;
                // フリーエリア
                TextBox TxtKubun = FindControl(this, "TxtKubun_" + i.ToString()) as TextBox;
                // 摘要（全角20文字以内）
                TextBox TxtTekiyou = FindControl(this, "TxtTekiyou_" + i.ToString()) as TextBox;

                List<string> rowInfoList = new List<string>();
                if (chk_select.Checked)
                {
                    rowInfoList.Add("1");

                    //入力内容用写入WEB画面（作業実績管理システム），首行ID从 _ctl02_ 开始
                    system_count += 1;
                    //作業コード（大）
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouCodeDai", TxtSagyouCodeDai.Text.Trim());
                    //作業コード（中）
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouCodeTyuu", TxtSagyouCodeTyuu.Text.Trim());
                    //作業コード（小）        
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouCodeSyou", TxtSagyouCodeSyou.Text.Trim());
                    //作業時間（分）          
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouJikan", TxtSagyouJikan.Text.Trim());
                    //EDP-NO                  
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtEDP", TxtEDP.Text.Trim());
                    //フリーエリア            
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtKubun", TxtKubun.Text.Trim());
                    //摘要（全角20文字以内）  
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtTekiyou", TxtTekiyou.Text.Trim());
                }
                else
                {
                    rowInfoList.Add("0");
                }
                rowInfoList.Add(TxtSagyouCodeDai.Text.Trim());
                rowInfoList.Add(TxtSagyouCodeTyuu.Text.Trim());
                rowInfoList.Add(TxtSagyouCodeSyou.Text.Trim());
                rowInfoList.Add(TxtSagyouJikan.Text.Trim());
                rowInfoList.Add(TxtEDP.Text.Trim());
                rowInfoList.Add(TxtKubun.Text.Trim());
                rowInfoList.Add(TxtTekiyou.Text.Trim());
                // Write Ini
                IniFunc.writeString("content", "row" + i.ToString(), string.Join(",", rowInfoList),Application.StartupPath + "\\WorkPerformance.ini");
            }
        }

        /// <summary>
        /// Check合計作業時間是否为470分（8小时）
        /// </summary>
        /// <returns></returns>
        private bool checkTotalWorkTime()
        {
            // 合計作業時間
            int TotalWorkTime = 0;
            for (int i = 1; i <= 5; i++)
            {
                // 将内容填写到画面的代填区域
                // chk_select
                CheckBox chk_select = FindControl(this, "chk_select_" + i.ToString()) as CheckBox;
                // 作業時間
                TextBox TxtSagyouJikan = FindControl(this, "TxtSagyouJikan_" + i.ToString()) as TextBox;
                if (chk_select.Checked)
                {
                    TotalWorkTime += convert_int(TxtSagyouJikan.Text.Trim());
                }
            }
            if (TotalWorkTime != 470)
            {
                MessageBox.Show("选择行的合計作業時間不等于470分（8小时）");
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 作業コード（大）（中）、作業時間（分）、摘要が必須項目
        /// </summary>
        /// <returns></returns>
        private bool checkNull()
        {
            for (int i = 1; i <= 5; i++)
            {
                // 将内容填写到画面的代填区域
                // chk_select
                CheckBox chk_select = FindControl(this, "chk_select_" + i.ToString()) as CheckBox;
                // 作業コード（大）
                TextBox TxtSagyouCodeDai = FindControl(this, "TxtSagyouCodeDai_" + i.ToString()) as TextBox;
                // 作業コード（中）
                TextBox TxtSagyouCodeTyuu = FindControl(this, "TxtSagyouCodeTyuu_" + i.ToString()) as TextBox;
                // 作業時間
                TextBox TxtSagyouJikan = FindControl(this, "TxtSagyouJikan_" + i.ToString()) as TextBox;
                // 摘要（全角20文字以内）
                TextBox TxtTekiyou = FindControl(this, "TxtTekiyou_" + i.ToString()) as TextBox;
                if (chk_select.Checked)
                {
                    if (string.IsNullOrWhiteSpace(TxtSagyouCodeDai.Text.Trim()) ||
                        string.IsNullOrWhiteSpace(TxtSagyouCodeTyuu.Text.Trim()) ||
                        string.IsNullOrWhiteSpace(TxtSagyouJikan.Text.Trim()) ||
                        string.IsNullOrWhiteSpace(TxtTekiyou.Text.Trim()))
                    {
                        MessageBox.Show("作業コード（大）（中）、作業時間（分）、摘要が必須項目です。");
                        return false;
                    }
                }
            }
            return true;
        }

        /// <summary>
        /// string to int
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        private int convert_int(string number)
        {
            try
            {
                return Convert.ToInt16(number.Trim());
            }
            catch(Exception ex)
            {
                return 0;
            }
        }

        /// <summary>
        /// 节假日时间自动填入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void holidayTimeInput(object sender, EventArgs e)
        {
            //日本休日的出社/退社時間默认都是 00：00
            if (GetValue("ctl00_ContentPlaceHolder1_TxtTuujyouSyussya") == "00:00" &&
                GetValue("ctl00_ContentPlaceHolder1_TxtTuujyouTaisya") == "00:00")
            {
                //出社時間
                inputValue("ctl00_ContentPlaceHolder1_TxtTuujyouSyussya", "08:00");
                //退社時間
                inputValue("ctl00_ContentPlaceHolder1_TxtTuujyouTaisya", "17:00");
                //控除時間
                inputValue("ctl00_ContentPlaceHolder1_TxtTuujyouKoujyo", "01:00");
                //点击一下入力框，触发JS，确定后无错误信息
                controlFocus("ctl00_ContentPlaceHolder1_TxtTuujyouSyussya");
                controlFocus("ctl00_ContentPlaceHolder1_GrdView_ctl03_TxtSagyouJikan");
                controlFocus("ctl00_ContentPlaceHolder1_TxtTuujyouKoujyo");
                //默认把第二行工作时间+10分（合计出勤时间470+10=480）
                string time_2 = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl03_TxtSagyouJikan");
                if (string.IsNullOrWhiteSpace(time_2) == false)
                {
                    inputValue("ctl00_ContentPlaceHolder1_GrdView_ctl03_TxtSagyouJikan", (convert_int(time_2) + 10).ToString());
                }
            }
        }

        /// <summary>
        /// 確定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF3_Click(object sender, EventArgs e)
        {
            // 出勤作業実績入力画面
            buttonClick("ctl00_ContentPlaceHolder1_cmdConfirm");
            // 出勤作業実績入力完了画面
            buttonClick("ctl00_ContentPlaceHolder1_btnOK");
        }

        /// <summary>
        /// 月度模式开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF6_Click(object sender, EventArgs e)
        {
            // Check合計作業時間是否为470分（8小时）
            if (this.checkTotalWorkTime() == false) return;
            // 作業コード（大）（中）、作業時間（分）、摘要が必須項目
            if (this.checkNull() == false) return;

            string text = "按照LIXIL大连信息系统部日历，自动填写本月未填写的出勤日的作業実績。\r\n请假，加班等请自行修改。\r\n(F7可停止)";
            if (MessageBox.Show(text, "一键填写一个月作業実績", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                tabControl11.SelectedIndex = 0;
                // 出勤日数据取得
                this.WORKDAYS = getCalendarList();

                timer1.Start();
                setButtonStatus(true);
            }
        }

        /// <summary>
        /// 月度模式结束
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF7_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            setButtonStatus(false);
        }

        /// <summary>
        /// 戻る
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF4_Click(object sender, EventArgs e)
        {
            //打开作业实际管理页
            tabControl11.SelectedIndex = 0;
            // 戻る
            buttonClick("ctl00_Lhsitory");
        }

        /// <summary>
        /// 中国万年历
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF11_Click(object sender, EventArgs e)
        {
            tabControl11.SelectedIndex = 1;
        }

        /// <summary>
        /// 使用帮助
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuF12_Click(object sender, EventArgs e)
        {
            tabControl11.SelectedIndex = 2;
        }

        /// <summary>
        /// 按名称查找控件
        /// </summary>
        /// <param name="parentControl">查找控件的父容器控件</param>
        /// <param name="findCtrlName">查找控件名称</param>
        /// <returns>若没有查找到返回NULL</returns>
        public Control FindControl(Control parentControl, string findCtrlName)
        {
            Control _findedControl = null;
            if (!string.IsNullOrEmpty(findCtrlName) && parentControl != null)
            {
                foreach (Control ctrl in parentControl.Controls)
                {
                    if (ctrl.Name.Equals(findCtrlName))
                    {
                        _findedControl = ctrl;
                        break;
                    }
                }
            }
            return _findedControl;
        }

        /// <summary>
        /// 网页加载失败时的处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void webBrowserCalendar_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            string documentText = webBrowserCalendar.DocumentText;
            if (documentText.IndexOf(",20")<0)
            {
                // 网页加载失败的时候，webBrowserCalendar不表示
                webBrowserCalendar.Visible = false;
                // 相关tabPage删除
                //tabControl11.TabPages.Remove(tabPage3);
            }
        }

        /// <summary>
        /// 日历页title设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void webBrowser3_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //tabControl11.TabPages[1].Text = webBrowser3.DocumentTitle;
        }

        /// <summary>
        /// 复制作业实际到左侧入力框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_copy_Click(object sender, EventArgs e)
        {
            //打开作业实际管理页
            tabControl11.SelectedIndex = 0;
            if (isExists("ctl00_ContentPlaceHolder1_GrdView_ctl02_TxtSagyouCodeDai"))
            {
                if (MessageBox.Show("复制后将覆盖左侧已入力内容，确认覆盖吗？", "复制前5行作業実績内容到左侧入力框", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                //作業コード（大）控件存在的时候
                // 作業実績管理システム入力行数
                int system_count = 1;

                for (int i = 1; i <= 5; i++)
                {
                    // 将内容填写到画面的代填区域
                    // chk_select
                    CheckBox chk_select = FindControl(this, "chk_select_" + i.ToString()) as CheckBox;
                    // 作業コード（大）
                    TextBox TxtSagyouCodeDai = FindControl(this, "TxtSagyouCodeDai_" + i.ToString()) as TextBox;
                    // 作業コード（中）
                    TextBox TxtSagyouCodeTyuu = FindControl(this, "TxtSagyouCodeTyuu_" + i.ToString()) as TextBox;
                    // 作業コード（小）
                    TextBox TxtSagyouCodeSyou = FindControl(this, "TxtSagyouCodeSyou_" + i.ToString()) as TextBox;
                    // 作業時間
                    TextBox TxtSagyouJikan = FindControl(this, "TxtSagyouJikan_" + i.ToString()) as TextBox;
                    // EDP NO
                    TextBox TxtEDP = FindControl(this, "TxtEDP_" + i.ToString()) as TextBox;
                    // フリーエリア
                    TextBox TxtKubun = FindControl(this, "TxtKubun_" + i.ToString()) as TextBox;
                    // 摘要（全角20文字以内）
                    TextBox TxtTekiyou = FindControl(this, "TxtTekiyou_" + i.ToString()) as TextBox;

                    //入力内容用写入WEB画面（作業実績管理システム），首行ID从 _ctl02_ 开始
                    system_count += 1;
                    //作業コード（大）
                    TxtSagyouCodeDai.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouCodeDai");
                    //作業コード（中）
                    TxtSagyouCodeTyuu.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouCodeTyuu");
                    //作業コード（小）        
                    TxtSagyouCodeSyou.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouCodeSyou");
                    //作業時間（分）          
                    TxtSagyouJikan.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtSagyouJikan");
                    //EDP-NO                  
                    TxtEDP.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtEDP");
                    //フリーエリア            
                    TxtKubun.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtKubun");
                    //摘要（全角20文字以内）  
                    TxtTekiyou.Text = GetValue("ctl00_ContentPlaceHolder1_GrdView_ctl0" + system_count.ToString() + "_TxtTekiyou");

                    List<string> rowInfoList = new List<string>();
                    if (string.IsNullOrEmpty(TxtSagyouCodeDai.Text) || string.IsNullOrEmpty(TxtSagyouJikan.Text) || string.IsNullOrEmpty(TxtTekiyou.Text))
                    {
                        //作業コード（大）、作業時間（分）、摘要が未入力の場合、チェックしない
                        chk_select.Checked = false;
                        rowInfoList.Add("0");
                    }
                    else
                    {
                        chk_select.Checked = true;
                        rowInfoList.Add("1");
                    }
                    rowInfoList.Add(TxtSagyouCodeDai.Text.Trim());
                    rowInfoList.Add(TxtSagyouCodeTyuu.Text.Trim());
                    rowInfoList.Add(TxtSagyouCodeSyou.Text.Trim());
                    rowInfoList.Add(TxtSagyouJikan.Text.Trim());
                    rowInfoList.Add(TxtEDP.Text.Trim());
                    rowInfoList.Add(TxtKubun.Text.Trim());
                    rowInfoList.Add(TxtTekiyou.Text.Trim());
                    // Write Ini
                    IniFunc.writeString("content", "row" + i.ToString(), string.Join(",", rowInfoList), Application.StartupPath + "\\WorkPerformance.ini");
                }
            }
            else
            {
                //作業コード（大）控件不存在的时候
                MessageBox.Show("请打开出勤作業実績入力画面","警告");
            }
        }

        /// <summary>
        /// 入力内容
        /// </summary>
        /// <param name="controlID"></param>
        /// <param name="value"></param>
        private void inputValue(string controlID, string value)
        {
            HtmlElement control = webBrowser1.Document.All[controlID];
            if (control == null) return;
            control.SetAttribute("value", value);
        }

        /// <summary>
        /// 取得内容
        /// </summary>
        /// <param name="controlID"></param>
        private string GetValue(string controlID)
        {
            HtmlElement control = webBrowser1.Document.All[controlID];
            if (control == null) return "";
            return control.GetAttribute("value");
        }

        /// <summary>
        /// ボタンをクリック
        /// </summary>
        /// <param name="controlID"></param>
        private void buttonClick(string controlID)
        {
            HtmlElement control = webBrowser1.Document.All[controlID];
            if (control == null) return;
            control.InvokeMember("click");
        }

        /// <summary>
        /// ボタンをFocus
        /// </summary>
        /// <param name="controlID"></param>
        private void controlFocus(string controlID)
        {
            HtmlElement control = webBrowser1.Document.All[controlID];
            if (control == null) return;
            control.Focus();
        }

        /// <summary>
        /// 判断是否是整数
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private bool isInt(object input)
        {
            if (input == null) return false;
            try
            {
                Convert.ToInt16(input);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 判断是否填写完成
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        private bool isDone(string html)
        {
            //背景色是deepskyblue,gray时，为已经填写完成
            if (html.IndexOf("BACKGROUND-COLOR: deepskyblue") > 0 || html.IndexOf("BACKGROUND-COLOR: gray") > 0)
            {
                // blue:入力済み、gray:入力不可（3月末、9月末）
                return true;
            }
            else
            {
                // yellow:入力途中、white:未入力
                return false;
            }
        }

        /// <summary>
        /// 判断是否是黑字
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        private bool isBlack(string html)
        {
            //黑字无color属性
            if (html.IndexOf("; COLOR:") < 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 判断控件是否存在
        /// </summary>
        /// <param name="controlID"></param>
        /// <returns></returns>
        private bool isExists(string controlID)
        {
            HtmlElement control = webBrowser1.Document.All[controlID];
            //黑字无color属性
            if (control != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// timer1_Tick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            //根据页面内容判断进程
            if (isExists("ctl00_ContentPlaceHolder1_btnInput"))
            {
                //MainMenu:出勤作業実績入力
                buttonClick("ctl00_ContentPlaceHolder1_btnInput");
            }
            else if (isExists("ctl00_ContentPlaceHolder1_TblCalendar"))
            {
                // 作業実績管理システム日历页
                HtmlElement table_calendar = webBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_TblCalendar");
                foreach (HtmlElement obj in table_calendar.All)
                {
                    string text = obj.InnerText;
                    string html = obj.OuterHtml;
                    if (html == null) continue;
                    //regex 
                    //onclick="fncSetDay('2021/12/07');"
                    string pattern = @"fncSetDay\('([0-9\/]{10})'\);";
                    string str_date = Regex.Match(html, pattern).Groups[1].Value;
                    Console.WriteLine(str_date);
                    if (WORKDAYS == null)
                    {
                        //从WEB取得工作日数据失败的时候，点击画面上的黑色日期文字
                        if (isInt(text) & isBlack(html) & isDone(html) == false)
                        {
                            //点击日期
                            obj.InvokeMember("click");
                            return;
                        }
                    }
                    else
                    {
                        if (isInt(text) & WORKDAYS.IndexOf(str_date.Replace("/", "")) >= 0 & isDone(html) == false)
                        {
                            //点击日期
                            obj.InvokeMember("click");
                            //调用JS点击日期
                            //webBrowser1.Document.InvokeScript("fncSetDay", new string[] { "2021/07/21" });
                            WORKDAYS.Remove(str_date.Replace("/", ""));
                            return;
                        }
                    }
                }
                timer1.Stop();
                setButtonStatus(false);
                //game over
                MessageBox.Show("请确认【累計(総時間)】是否正确\r\n请假，加班等请自行修改！", "本月入力完了");

            }
            else if (isExists("ctl00_ContentPlaceHolder1_cmdConfirm"))
            {
                // 出勤作業実績入力
                // 偷懒模式填入
                this.WriteIni();
                // 节假日时间自动填入(自动把第二行工作时间+10分（合计出勤时间470+10=480）)
                holidayTimeInput(null, null);
                //確定
                buttonClick("ctl00_ContentPlaceHolder1_cmdConfirm");
            }
            else if (isExists("ctl00_ContentPlaceHolder1_btnOK"))
            {
                //出勤作業実績入力完了。
                //確定
                buttonClick("ctl00_ContentPlaceHolder1_btnOK");
            }
        }

        /// <summary>
        /// 从api.book1.vip取得出勤日数据（通过浏览器，无需代理）
        /// </summary>
        /// <returns></returns>
        private List<string> getCalendarList()
        {
            string content = this.webBrowserCalendar.DocumentText;
            if (content.IndexOf(",20") >= 0)
            {
                // 从WEB取得数据成功时
                return content.Split(',').ToList();
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// timer开始后，start button不可用；结束后，stop button不可用
        /// </summary>
        /// <param name="startFlag">true:开始、false:结束</param>
        private void setButtonStatus(bool startFlag)
        {
            this.menuF6.Enabled = !startFlag;
            this.menuF7.Enabled = startFlag;
        }
    }
}
